#include "simplefocfindpacket.h"
#include "misc.h"

SimpleFOCFindPacket::SimpleFOCFindPacket(QObject *parent)
    : BaseFindPacket (parent)
{

}

SimpleFOCFindPacket::~SimpleFOCFindPacket()
{

}

QList<ProtocolPacket> SimpleFOCFindPacket::find(const QByteArray &data)
{
    m_rxBuffer.append(data);

    QList<ProtocolPacket>   packets;
    while (!m_rxBuffer.isEmpty())
    {
        char _data = m_rxBuffer.at(0);
        m_rxBuffer.remove(0, 1);//移除头字节

        m_rxPacket.append(_data);

        if (_data == '\n') // 包尾
        {
            ProtocolPacket packet;
            packet.timestamp = Misc::getTimeStamp();
            packet.buffer = m_rxPacket;
            packets << packet;

            m_rxPacket.clear();
        }
    } // while

    return packets;
}
